﻿@model Clirelmgt.Models.MetaProcessPage

@{
    ViewBag.Title = "Card";
    string lang = Clirelmgt.Manager.Utility.GetLanguage(Session["crmsession"]);
}

@if (Model.GlobalScripts != null)
{
    <script type="text/javascript">    
        @foreach (var script in Model.GlobalScripts)
        {
            string jsScript = string.Format("function {0}({1})", script.Name, script.InputParam);
            jsScript += "{" + script.ScriptValue + "}\n";
            @Html.Raw(jsScript)
        }
    </script>
}

<div class="sub-nav">
    <ul>
        <li><a href="" class="heading">Forms</a></li>
        @foreach (var group in Model.FieldGroups)
        {
            <li>
                <a href="#@group.Name.Replace(" ", "")">@group.Name
                </a>
            </li>
        }
    </ul>
</div>
<div class="dashboard-wrapper">
    <div class="left-sidebar">
        <div class="row-fluid">
            <div class="span12">
                <div class="widget">
                    <div class="widget-header">
                        <div class="title">
                            @Model.Name
                            <span class="mini-title">@Model.Description</span>
                        </div>
                        <span class="tools">
                            <a class="fs1" aria-hidden="true" data-icon="&#xe090;"></a>
                        </span>
                    </div>
                    <div class="widget-body">
                        <form class="form-horizontal no-margin" method="post">
                            @foreach (var fieldGroup in Model.FieldGroups)
                            {
                                <h5 id="@fieldGroup.Name.Replace(" ", "")">@fieldGroup.Name</h5>
                                <hr />
                                foreach (var field in fieldGroup.Fields)
                                {
                                    string label = "";
                                    var langs = field.Labels.Where(obj => (obj.LangID == lang)).ToList();
                                    if (langs.Count > 0)
                                    {
                                        label = langs[0].LabelText;
                                    }
                                    else
                                    {
                                        label = field.Labels[0].LabelText;
                                    }
                                    
                                <div class="control-group">
                                    <label class="control-label" for="name">
                                        @label
                                    </label>
                                    <div class="controls controls-row">
                                        @if (field.DataType == Clirelmgt.Models.FieldDataType.Select)
                                        {
                                            string query = string.Format("SELECT [CodeValue] FROM MasterData WHERE MasterCode='{0}'", field.Options);
                                            System.Data.DataSet ds = Clirelmgt.Manager.DataAccess.RunSelectStatement(query);
                                            <select data-val="@field.Required.ToString().ToLowerInvariant()" data-val-required="Required!"  id="@field.Name" name="@field.Name">
                                                <option value=""></option>
                                                @if (ds != null && ds.Tables.Count > 0)
                                                {
                                                    foreach (System.Data.DataRow row in ds.Tables[0].Rows)
                                                    {
                                                        if (field.FieldValue != null && field.FieldValue.ToString() == row[0].ToString())
                                                        {
                                                    <option value="@row[0].ToString()" selected>@row[0].ToString()</option>
                                                        }
                                                        else
                                                        {
                                                    <option value="@row[0].ToString()">@row[0].ToString()</option>
                                                        }
                                                    }
                                                }
                                            </select>
                                        }
                                        else if (field.DataType == Clirelmgt.Models.FieldDataType.Table)
                                        {
                                            string query = "SELECT [{0}],[{1}] FROM [{2}]";
                                            query = string.Format(query, "No", "Description", field.Options);
                                            System.Data.DataSet ds = Clirelmgt.Manager.DataAccess.RunSelectStatement(query);
                                            <select data-val="@field.Required.ToString().ToLowerInvariant()" data-val-required="Required!"  id="@field.Name" name="@field.Name">
                                                <option value=""></option>
                                                @if (ds != null && ds.Tables.Count > 0)
                                                {
                                                    foreach (System.Data.DataRow row in ds.Tables[0].Rows)
                                                    {
                                                        if (field.FieldValue != null && field.FieldValue.ToString() == row[0].ToString())
                                                        {
                                                    <option value="@row[0].ToString()" selected>@row[1].ToString()</option>
                                                        }
                                                        else
                                                        {
                                                    <option value="@row[0].ToString()">@row[1].ToString()</option>
                                                        }
                                                    }
                                                }
                                            </select>
                                        }
                                        else if (field.DataType == Clirelmgt.Models.FieldDataType.Bool)
                                        {
                                            string checkValue = "";
                                            if (field.FieldValue != null && field.FieldValue.ToString().ToLowerInvariant() == "true")
                                            {
                                            <input type="checkbox" id="@field.Name" name="@field.Name" checked="checked" />
                                            }
                                            else
                                            {
                                            <input type="checkbox" id="@field.Name" name="@field.Name" />
                                            }
                                        }
                                        else if (field.DataType == Clirelmgt.Models.FieldDataType.MultilineText)
                                        {
                                            <textarea id="@field.Name" class="span7" rows="4" name="@field.Name" data-val="@field.Required.ToString().ToLowerInvariant()" data-val-required="Required!" placeholder="Please enter @label.ToLowerInvariant()" value="@field.FieldValue" ></textarea>
                                        }
                                        else
                                        {
                                            if (field.DataType == Clirelmgt.Models.FieldDataType.Key)
                                            {
                                            <input class="span4" type="text" id="@field.Name" name="@field.Name" data-val="@field.Required.ToString().ToLowerInvariant()" data-val-required="Required!" disabled="disabled" placeholder="Please enter @label.ToLowerInvariant()" value="@ViewBag.No" />                                                
                                            }
                                            else
                                            {
                                            <input class="span4" type="@field.DataType.ToString().ToLower()" id="@field.Name" name="@field.Name" data-val="@field.Required.ToString().ToLowerInvariant()" data-val-required="Required!"  placeholder="Please enter @label.ToLowerInvariant()" value="@field.FieldValue" />
                                            }
                                        }

                                        <span class="field-validation-valid" data-valmsg-for="@field.Name" data-valmsg-replace="true"></span>
                                    </div>
                                </div>
                                }
                            }
                            <div class="form-actions no-margin">
                                @if (Model.Buttons != null)
                                {
                                    foreach (var item in Model.Buttons)
                                    {
                                    <button type="submit" id="btn_@item.Name" name="btn_@item.Name" class="btn btn-info pull-right">
                                        @item.Name
                                    </button>  
                                        Html.Raw("&nbsp;");
                                    }
                                }

                            </div>
                        </form>
                    </div>



                </div>
            </div>
        </div>

    </div>
    <div class="right-sidebar">

    <div class="wrapper">
        <button class="btn btn-block btn-info" type="button">
            Block level button
             
        </button>
    </div>
    <div class="wrapper">
        <button class="btn btn-block btn-success" type="button">
            Block level button
             
        </button>
    </div>
    <div class="wrapper">
        <button class="btn btn-block btn-warning" type="button">
            Block level button
             
        </button>
    </div>

    <hr class="hr-stylish-1">

    <div class="wrapper">
        <ul class="progress-statistics">
            <li>
                <div class="details">
                    <span>Windows
                    </span>
                    <span class="pull-right">78%
                    </span>
                </div>
                <div class="progress">
                    <div class="bar" style="width: 78%;">
                    </div>
                </div>
            </li>
            <li>
                <div class="details">
                    <span>Windows 8
                    </span>
                    <span class="pull-right">32%
                    </span>
                </div>
                <div class="progress progress-success">
                    <div class="bar" style="width: 32%;">
                    </div>
                </div>
            </li>
            <li>
                <div class="details">
                    <span>Mac
                    </span>
                    <span class="pull-right">84%
                    </span>
                </div>
                <div class="progress progress-warning">
                    <div class="bar" style="width: 84%;">
                    </div>
                </div>
            </li>
            <li>
                <div class="details">
                    <span>Linux
                    </span>
                    <span class="pull-right">44%
                    </span>
                </div>
                <div class="progress progress-danger">
                    <div class="bar" style="width: 44%;">
                    </div>
                </div>
            </li>
            <li>
                <div class="details">
                    <span>IPhone/IPad
                    </span>
                    <span class="pull-right">67%
                    </span>
                </div>
                <div class="progress progress-info">
                    <div class="bar" style="width: 67%;">
                    </div>
                </div>
            </li>
        </ul>
    </div>

    <hr class="hr-stylish-1">

    <div class="wrapper">
        <div class="btn-toolbar no-margin">
            <div class="btn-group">
                <a href="#" class="btn btn-success">
                    <i class="icon-white icon-headphones"></i>
                </a>
                <a href="#" class="btn btn-warning">
                    <i class="icon-white icon-thumbs-down"></i>
                </a>
                <a href="#" class="btn btn-warning2">
                    <i class="icon-white icon-tasks"></i>
                </a>
                <a href="#" class="btn btn-info">
                    <i class="icon-white icon-hand-left"></i>
                </a>
            </div>
            <div class="btn-group">
                <a href="#" class="btn btn-inverse">
                    <i class="icon-white icon-trash"></i>
                </a>
            </div>
        </div>
    </div>

</div>
</div>



@*@foreach (var fieldGroup in Model.FieldGroups)
{
    foreach (var field in fieldGroup.Fields)
    {
        if (field.glo != null)
        {
            foreach (var eve in field.ClientScripts)
            {
    <script type="text/javascript">
        $(function(){
            $("#@field.Name").@eve.Name
                    ( function() {
                        @Html.Raw(eve.ScriptValue)
                    });
                });
    </script>
            }
        }
    }
}*@